package core.util;

public class DatePeriod {

	public static int getPeriodMonthsBefore(StringHashMap map, int chart_period) {
		int period_before;
		Object temp_this_month = map.get("this_month");

		if (temp_this_month != null) { // month
			int this_year1 = map.getIntValue("this_year1");
			int this_month1 = map.getIntValue("this_month1");

			if (chart_period == -1) { // year to date
				period_before = this_year1 * 100 + 1;

			} else {
				int now1 = this_year1 * 12 + this_month1;

				int before = now1 - chart_period;
				period_before = (before / 12) * 100 + (before % 12);
			}

		} else { // week
			int this_year1 = map.getIntValue("this_year1");
			int this_week1 = map.getIntValue("this_week1");

			if (this_week1 < 6)
				period_before = (this_year1 - 1) * 100 + this_year1; // -5 + 52
			else
				period_before = this_year1 * 100 + this_week1 - 5;
		}
		return period_before;
	}
}
